﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 晨曦超市管理系统.员工管理
{
    public partial class Staff : Form
    {
        public Staff()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            YuanAdd1 YuanAdd = new YuanAdd1();
            YuanAdd.ShowDialog();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            DialogResult sahnchu = MessageBox.Show(this, "确定要删除选中行数据码？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            switch (sahnchu)
            {
                case DialogResult.No:
                    break;
                case DialogResult.Yes:
                    for (int i = this.dataGridView1.SelectedRows.Count; i > 0; i--)
                    {
                        string ID =(dataGridView1.SelectedRows[i - 1].Cells[0].Value).ToString();
                        //也可以转成string的

                        //int ID = Convert.ToInt32(dataGridView1.SelectedRows[i - 1].Cells[0].Value);
                        //这个他把obj值转成了int了
                        dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index);
                        string SQL = "delete from informationOfEmployees where Name='" + ID+ "'";//主要是这里取到了我选中的值
                        bool s =DBHelper.QEX(SQL);
                        if (s)
                        {
                            MessageBox.Show("成功删除选中行数据！");
                        }
                    }
                    break;
            }
        }
        public DataTable tale;
        private void Staff_Load(object sender, EventArgs e)
        {
            string sqlstr = "select * from informationOfEmployees";
            Reusing.XianShi(dataGridView1, sqlstr, tale);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            string sqlstr = "select * from informationOfEmployees";
            Reusing.ShuXin(dataGridView1, sqlstr, tale);
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Modification2 moFrm = new Modification2();
            moFrm.dr = dataGridView1.SelectedRows[0];
            moFrm.ShowDialog();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Modification2 moFrm = new Modification2();
            moFrm.dr = dataGridView1.SelectedRows[0];
            moFrm.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sqlstr = "select * from informationOfEmployees where  Name='" + textBox1.Text.Trim() + "'";
            Reusing.XianShi(dataGridView1, sqlstr, tale);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Essential Essential = new Essential();
            Essential.ShowDialog();
        }
    }
}
